package com.iu.controller;

import com.iu.bean.UserBean;
import com.iu.service.IUserLoginService;
import com.iu.service.UserLoginService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
public class UserAction {
    @Resource
    IUserLoginService userLoginService;
    @RequestMapping("/doLogin")
    public ModelAndView doLogin(UserBean userBean){
        //控制台输出浏览器输入获取到数据
        System.out.println("账号："+userBean.getUserName()+" 密码："+userBean.getUserPassword());
        ModelAndView modelAndView= new ModelAndView();//是否ModelAndView也可托管spring容器？
        boolean isOk=userLoginService.doLogin(userBean);
        if(isOk){
            modelAndView.setViewName("logined");
            //缓存用户名
            modelAndView.addObject("loginedName",userBean.getUserName());

        }else{
            modelAndView.setViewName("../../index");//../表示退上级目录
        }
        return modelAndView;
    }
}
